/*
 * 1466. 链表节点计数
 * 计算链表中有多少个节点.
 * https://www.lintcode.com/problem/count-linked-list-nodes/description
 * 
 * 样例
 * 给出 1->3->5, 返回 3.
 * 
 * 2018.06.10 @jeyming
 */
package count_linked_list_nodes_1466;

//Definition for ListNode
class ListNode {
	int val;
	ListNode next;
	ListNode(int x) {
		val = x;
		next = null;
	}
}

public class Count_linked_list_nodes_1466 {

	 /**
     * @param head: the first node of linked list.
     * @return: An integer
     */
    public int countNodes(ListNode head) {
        // write your code here
    	int cnt = 0;
    	while(head != null) {
    		cnt++;
    		head = head.next;
    	}
    	return cnt;
    }
    
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
